package org.tuoren.official.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.tuoren.common.idempotent.annotation.RepeatSubmit;
import org.tuoren.common.log.annotation.Log;
import org.tuoren.common.web.core.BaseController;
import org.tuoren.common.mybatis.core.page.PageQuery;
import org.tuoren.common.core.domain.R;
import org.tuoren.common.core.validate.AddGroup;
import org.tuoren.common.core.validate.EditGroup;
import org.tuoren.common.log.enums.BusinessType;
import org.tuoren.common.excel.utils.ExcelUtil;
import org.tuoren.official.domain.vo.FounderVo;
import org.tuoren.official.domain.bo.FounderBo;
import org.tuoren.official.service.IFounderService;
import org.tuoren.common.mybatis.core.page.TableDataInfo;

/**
 * 创始人信息
 *
 * @author wl
 * @date 2024-11-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/official/founder")
public class FounderController extends BaseController {

    private final IFounderService founderService;


    /**
     * 前台-查询创始人信息
     */
    @SaIgnore
    @GetMapping("/frontList")
    public R<FounderVo> frontList() {
        return R.ok(founderService.frontList());
    }

    /**
     * 查询创始人信息
     */
    @SaCheckPermission("official:founder:list")
    @GetMapping("/list")
    public R<FounderVo> list(FounderBo bo) {
        return R.ok(founderService.queryList(bo).get(0));
    }

    /**
     * 获取创始人信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("official:founder:query")
    @GetMapping("/{id}")
    public R<FounderVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(founderService.queryById(id));
    }

    /**
     * 修改创始人信息
     */
    @SaCheckPermission("official:founder:edit")
    @Log(title = "创始人信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FounderBo bo) {
        return toAjax(founderService.updateByBo(bo));
    }
}
